﻿#include "CustomTreeViewModel.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <qstandarditemmodel.h>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initData()
{
    CustomTreeViewModel *model = new CustomTreeViewModel();

    CustomTreeViewModel::fileNodeInfo nodeinfo;
    nodeinfo.name = "parent1";
    nodeinfo.bcheck = false;
    for (int i = 0; i < 100; i++)
    {
        CustomTreeViewModel::fileNodeInfo *childNode = new CustomTreeViewModel::fileNodeInfo();
        childNode->name = QString::number(i);

        for (int j = 0; j < 50; ++j)
        {
            CustomTreeViewModel::fileNodeInfo *childNode2 = new CustomTreeViewModel::fileNodeInfo();
            childNode2->name = QString::number(j);
            childNode2->bcheck = true;
            childNode->m_childNode.append(*childNode2);
        }
        nodeinfo.m_childNode.append(*childNode);
    }
    model->setFileData(&nodeinfo);
    ui->treeView->setModel(model);
}

void MainWindow::on_pushButton_clicked()
{
    initData();
}
